package test;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

import jodd.http.HttpRequest;
import jodd.http.HttpResponse;
import junit.framework.TestCase;

import org.jsbd.boss.util.GetIpAddress;
import org.jsbd.boss.util.HttpUtil;
import org.jsbd.boss.util.MathUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;

public class TaskTestCase extends TestCase {

    @Before
    public void setUp() throws Exception {

    }

    @After
    public void tearDown() throws Exception {
    }

    @Test
    public void testPOST() {
        File file=new File("E:\\网盟事业部\\测试\\模拟测试\\获取短信参数.txt");
        try {
			BufferedReader reader=new BufferedReader(new FileReader(file));
			StringBuffer buffer=new StringBuffer();
			String content=null;
			while ((content=reader.readLine())!=null){
				buffer.append(content);
			}
			reader.close();
			
			JSONObject object=JSON.parseObject(buffer.toString());
			
			String imsi="46000"+MathUtils.getRandomString(10);
//			object.put("imsi", "460008122304817");
			
			object.put("imsi",imsi);
			System.out.println(imsi);
			String obtainSmsUrl="http://localhost:8800/apktask/obtainSms";
			Map<String,String> paramMap=new HashMap<String,String>();
			paramMap.put("result", object.toJSONString());
			Map<String,String> result=GetIpAddress.getInfoByMapAndPost(obtainSmsUrl, paramMap, 6000);
			System.out.println(result);
		} catch (IOException e) {
			
		}
    }

    
    
    @Test
    public void testSimulator() {
        File file=new File("E:\\网盟事业部\\测试\\模拟测试\\获取短信参数.txt");
        try {
			BufferedReader reader=new BufferedReader(new FileReader(file));
			StringBuffer buffer=new StringBuffer();
			String content=null;
			while ((content=reader.readLine())!=null){
				buffer.append(content);
			}
			reader.close();
			
			JSONObject object=JSON.parseObject(buffer.toString());
			
			String imsi="46000"+MathUtils.getRandomString(10);
//			object.put("imsi", "460008122304817");
			
			object.put("imsi",imsi);
			System.out.println(imsi);
			String obtainSmsUrl="http://localhost:8800/apktask/getTask";
			Map<String,String> paramMap=new HashMap<String,String>();
			paramMap.put("uuid", "");
			paramMap.put("sysVer", "1.0");
			
			paramMap.put("result", object.toJSONString());
			Map<String,String> result=GetIpAddress.getInfoByMapAndPost(obtainSmsUrl, paramMap, 6000);
			System.out.println(result);
		} catch (IOException e) {
			
		}
    }
    
    
}
